package Demo;

import java.util.LinkedList;
import java.util.List;

public class Student {
    private int id;
    private String name;
    private List<Double> scores;//用链表存储成绩

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
        this.scores = new LinkedList<>();//链表初始化
    }
    public void addScore(double s){
//        添加成绩
     scores.add(s);
    }

    public double calculateAverage(){
//        求平均值
        if (scores.isEmpty()) return 0;
        double sum = 0;
        for (double s :scores){
            sum += s;
        }
        return sum/scores.size();
    }
    @Override
    public String toString() {
        return id + ", " + name + ", Scores: " + scores + ", Average: " + calculateAverage();
    }
}
